﻿#ifndef QSLOGWIDGET_H
#define QSLOGWIDGET_H

#pragma once

#include <QObject>
#include <QTableView>
#include <QTableWidget>
#include <QStyledItemDelegate>
#include <QModelIndex>
#include "qslog_table_model.h"
#include "qslog/QsLog.h"
#include <QPainter>
#include <QApplication>
#include <QStyle>


class QsLogItemDelegate;
class QsLogWidget : public QObject
{
    Q_OBJECT
public:
    QsLogWidget(QObject *parent = Q_NULLPTR);
    void setTableView(QTableView *tableview);
    void setHistoryData(QStringList& his);


public slots:
    void disAll();
    void disInfo();
    void disWarn();
    void disFatal();

    int getDisLevel()
    {
        return logModel->getDisLevel();
    }

    void setDisLevel(int level)
    {
        logModel->setDisLevel(level);
    }

    void clear()
    {
        int level = logModel->getDisLevel();
        logModel->clearDisLevel(level);
    }

    void addLog(QString message);

private:
    QsLogTableModel *logModel;
    QTableView *logView;
    QsLogItemDelegate *logDelegate;
};
class QsLogItemDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    QsLogItemDelegate(QObject* parent = 0);
    void paint(QPainter *painter, const QStyleOptionViewItem &option,
               const QModelIndex &index) const Q_DECL_OVERRIDE;

};
#endif // QSLOGWIDGET_H
